package com.mebs.edi.datalayer.jpa;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.mebs.edi.datalayer.EdiIsaDao;
import com.mebs.edi.model.edi.EdiIsa;
import com.mebs.model.logistics.Transportation;

public class JpaEdiIsaDao extends JpaGenericDao implements EdiIsaDao {

	public EdiIsa getByTransportation(Transportation t) {
		EntityManager em = getEntityManager();
		
		String queryString = 
			"select i from EdiIsa i where (" +
				"select g from EdiGs g where (" +
					"select s from Edi211St s where s.transportation = :transportation" +
				") member of g.stSections" +
			") member of i.gs";
		
		TypedQuery<EdiIsa> query = em
			.createQuery(queryString, EdiIsa.class)
			.setParameter("transportation", t);
		
		EdiIsa ediIsa = query.getSingleResult();
		return ediIsa;
	}

}
